﻿using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Windows.Log.Domain;
using Windows.Log.Infrastructure.EFCore;
using Windows.Service.Share;
using Windows.Infrastructure.EFCore.Share.Extensions;
using AutoMapper;

namespace Windows.Log.Service
{
    public class LogSignInService : ILogSignInService
    {
        private readonly LogDbContext _db;
        private readonly IMapper _mapper;
        public LogSignInService(LogDbContext db, IMapper mapper)
        {
            _mapper = mapper;
            _db = db;
        }
        /// <summary>
        /// 获取登录日志列表
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public async Task<PageResponse<LogSignInResponse>> Query(PageRequest info)
        {
            var query = _db.LogSignIn.AsNoTracking();
            int totalCount = await query.CountAsync();
            List<LogSignIn> list = await query.Paging(info.PageIndex, info.PageSize).ToListAsync();
            PageResponse<LogSignInResponse> model = new()
            {
                PageIndex = info.PageIndex,
                PageSize = info.PageSize,
                TotalCount = totalCount,
                List = _mapper.Map<List<LogSignInResponse>>(list)
            };
            return model;
        }
    }
}
